# Contributor: Díaz Urbaneja Diego <sodomon2@gmail.com>
# Maintainer: Díaz Urbaneja Diego <sodomon2@gmail.com>
pkgname=paho-mqtt-c
pkgver=1.3.13
pkgrel=0
pkgdesc="Fully fledged MQTT client written in ANSI standard C"
url="https://www.eclipse.org/paho/clients/c/"
arch="all"
license="EPL-1.0"
makedepends="cmake openssl-dev samurai"
subpackages="$pkgname-dev $pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/eclipse/paho.mqtt.c/archive/v$pkgver.tar.gz"
builddir="$srcdir/paho.mqtt.c-$pkgver"
options="!check" # todo

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=None \
		-DPAHO_WITH_SSL=TRUE \
		-DPAHO_ENABLE_TESTING="$(want_check && echo ON || echo OFF)" \
		$CMAKE_CROSSOPTS
	cmake --build build
}

check() {
	ctest --test-dir build --output-on-failure
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	# install man pages
	install -Dm644 docs/*/man/man3/*.3 \
		-t "$pkgdir"/usr/share/man/man3/
}

sha512sums="
0f436470bcff224461ed3227c8db10914f84bc2dcf76e51b55d4a78b80abaa4e636ac8f7a20e517524625888335c738e975283e5d573ae8d59147aa4de7963fc  paho-mqtt-c-1.3.13.tar.gz
"
